$(function () {
    info();
    $("#select").click(function () {
        select();
    });
    //点击下一页
    $("#nextPage").click(function () {
        if ($("#thisPage").text()==$("#sumPage").text()) {
            alert("当前页已经是最后一页!!!")
        }else{
            var page=$("#thisPage").text();
            page= parseInt(page);
            var nextPage=page+1;
            $("#thisPage").text(nextPage);
            lastAndNextPages(page);
        }
    });
    //点击上一页
    $("#lastPage").click(function () {
        if ($("#thisPage").text()==1) {
            alert("当前页已经是第一页!!!")
        }else{
            var page1=$("#thisPage").text();//当前页
            page1= parseInt(page1);
            var lastPage=page1-2;
            $("#thisPage").text(lastPage);
            var page=$("#thisPage").text();
            lastAndNextPages(page);
        }
    })
})
function lastAndNextPages(page) {
    var status=$('#status option:selected') .val();//选中的值   商品状态
    $("#showTable").html("");
    $.getJSON("/UserController/testPage","commodityName="+commodityName+"&cityId="+cityId+"&typeId="+typeId+"&status="+status+"&star="+star+"&isSeat="+isSeat+"&page="+page, function (result) {
        var thisPage=result.number;
        var sumPage=result.totalPages;
        $("#thisPage").text(thisPage+1);
        $("#sumPage").text(sumPage);
        $.each(result.content, function (i, e) {
            var status= e.status;//状态
            var status1="";
            if (status==0){
                status1="下架";
            }else if (status==1){
                status1="上架";
            }else if (status==2){
                status1="暂停售卖";
            }else if (status==3){
                status1="过期";
            }
            var isSeat= e.isSeat;//是否可选择座位,0不能，1能
            var Seat="";
            if (isSeat==1){
                Seat="是";
            }else {
                Seat="否";
            }
            $("#showTable").append("<tr>\n" +
                "                            <td width=\"25px\"><label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label></td>\n" +
                "                            <td width=\"50px\">"+e.commodityId+"</td>\n" +
                "                            <td width=\"50px\">"+e.typeId+"</td>\n" +
                "                            <td width=\"120px\">"+e.cityId+"</td>\n" +
                "                            <td width=\"120px\">"+e.placeId+"</td>\n" +
                "                            <td width=\"180px\">"+e.commodityName+"</td>\n" +
                "                            <td width=\"180px\">"+e.startTime+"</td>\n" +
                "                            <td width=\"100px\">"+e.star+"</td>\n" +
                "                            <td width=\"80px\">"+status1+"</td>\n" +
                "                            <td width=\"80px\">"+Seat+"</td>\n" +
                "                            <td width=\"80px\">"+e.buyAmount+"</td>\n" +
                "                            <td class=\"td-manage\">\n" +
                "                                <a onClick=\"member_stop(this,'10001')\"  href=\"javascript:;\" title=\"下架\"  class=\"btn btn-xs btn-status\">下架</a>\n" +
                "                                <a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" >编辑</a>\n" +
                "                                <a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-delete\" >删除</a>\n" +
                "                            </td>\n" +
                "                        </tr>");

        });
    });
}
function select() {
    var commodityName=$("#commodityName").val();//商品名称
    var cityId=$('#cityList option:selected') .val();//选中的值     城市
    var typeId=$('#typeList option:selected') .val();//选中的值     类型
    var status=$('#statusList option:selected') .val();//选中的值   商品状态
    var  star=$('#starList option:selected') .val();//选中的值   商品评星
    var  isSeat=$('#isSeatList option:selected') .val();//选中的值   是否可以选座
    $("#showTable").html("");
    $.getJSON("/commodityController/testPage","commodityName="+commodityName+"&cityId="+cityId+"&typeId="+typeId+"&status="+status+"&star="+star+"&isSeat="+isSeat, function (result) {
        var thisPage=result.number;
        var sumPage=result.totalPages;
        $("#thisPage").text(thisPage+1);
        $("#sumPage").text(sumPage);
        $.each(result.content, function (i, e) {
            var status= e.status;//状态
            var status1="";
            if (status==0){
                status1="下架";
            }else if (status==1){
                status1="上架";
            }else if (status==2){
                status1="暂停售卖";
            }else if (status==3){
                status1="过期";
            }
            var isSeat= e.isSeat;//是否可选择座位,0不能，1能
            var Seat="";
            if (isSeat==1){
                Seat="是";
            }else {
                Seat="否";
            }
            $("#showTable").append("<tr>\n" +
                "                            <td width=\"25px\"><label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label></td>\n" +
                "                            <td width=\"50px\">"+e.commodityId+"</td>\n" +
                "                            <td width=\"50px\">"+e.typeId+"</td>\n" +
                "                            <td width=\"120px\">"+e.cityId+"</td>\n" +
                "                            <td width=\"120px\">"+e.placeId+"</td>\n" +
                "                            <td width=\"180px\">"+e.commodityName+"</td>\n" +
                "                            <td width=\"180px\">"+e.startTime+"</td>\n" +
                "                            <td width=\"100px\">"+e.star+"</td>\n" +
                "                            <td width=\"80px\">"+status1+"</td>\n" +
                "                            <td width=\"80px\">"+Seat+"</td>\n" +
                "                            <td width=\"80px\">"+e.buyAmount+"</td>\n" +
                "                            <td class=\"td-manage\">\n" +
                "                                <a onClick=\"member_stop(this,'10001')\"  href=\"javascript:;\" title=\"下架\"  class=\"btn btn-xs btn-status\">下架</a>\n" +
                "                                <a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" >编辑</a>\n" +
                "                                <a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-delete\" >删除</a>\n" +
                "                            </td>\n" +
                "                        </tr>");

        });
    });
}

function  info() {
    $("#showTable").html("");
    $.getJSON("/commodityController/testPage", function (result) {

        var thisPage=result.number;
        var sumPage=result.totalPages;
        $("#thisPage").text(thisPage+1);
        $("#sumPage").text(sumPage);
        $.each(result.content, function (i, e) {

            var status= e.status;//状态
            var status1="";
            if (status==0){
                status1="下架";
            }else if (status==1){
                status1="上架";
            }else if (status==2){
                status1="暂停售卖";
            }else if (status==3){
                status1="过期";
            }
            var isSeat= e.isSeat;//是否可选择座位,0不能，1能
            var Seat="";
            if (isSeat==1){
                Seat="是";
            }else{
                Seat="否";
            }
            $("#showTable").append("<tr>\n" +
                "                            <td width=\"25px\"><label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label></td>\n" +
                "                            <td width=\"50px\">"+e.commodityId+"</td>\n" +
                "                            <td width=\"50px\">"+e.typeId+"</td>\n" +
                "                            <td width=\"120px\">"+e.cityId+"</td>\n" +
                "                            <td width=\"120px\">"+e.placeId+"</td>\n" +
                "                            <td width=\"180px\">"+e.commodityName+"</td>\n" +
                "                            <td width=\"180px\">"+e.startTime+"</td>\n" +
                "                            <td width=\"100px\">"+e.star+"</td>\n" +
                "                            <td width=\"80px\">"+status1+"</td>\n" +
                "                            <td width=\"80px\">"+Seat+"</td>\n" +
                "                            <td width=\"80px\">"+e.buyAmount+"</td>\n" +
                "                            <td class=\"td-manage\">\n" +
                "                                <a onClick=\"member_stop(this,'10001')\"  href=\"javascript:;\" title=\"下架\"  class=\"btn btn-xs btn-status\">下架</a>\n" +
                "                                <a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" >编辑</a>\n" +
                "                                <a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-delete\" >删除</a>\n" +
                "                            </td>\n" +
                "                        </tr>");

        });
    });
}